package com.icebartech.core.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;

/**
 * Created by wl on 2017/9/4.
 */
public class RandomCode {
    //随机字符集
    private static final String [] RANDOM_MAP = {"1","2","3","4","5","6","7","8","9",
            "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
            "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"
    };

    /**
     * 获取指定长度的随机数字字母的组合串
     * @param length 长度
     * @return
     */
    public static String getRandomCharAndNumr(Integer length) {
        StringBuffer str = new StringBuffer();
        int codeLength = RANDOM_MAP.length;
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            str.append(RANDOM_MAP[random.nextInt(codeLength)]);
        }
        return str.toString();
    }

   public static void main(String[] args){
       ArrayList<String> a = new ArrayList<>();
       for (int i=0;i<1000;i++){
           String s = getRandomCharAndNumr(16);
           if(a.contains(s)){
               break;
           }else{
               a.add(s);
               System.out.println(s+"--------------"+i);
           }
       }
   }
}
